<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增公司')"/>
    <th:block th:include="include :: select2-css"/>
</head>
<body>
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-role-edit">
        <div class="form-group">
            <label class="col-sm-3 control-label ">公司编号：</label>
            <div class="col-sm-8">
                <input class="form-control" onkeyup="value=value.replace(/[^\w\.\/]/ig,'')" type="text" name="compCode" id="compCode" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">公司名称：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="title" id="title" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">简称：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="compAbbr" id="compAbbr" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">上级公司：</label>
            <div class="col-sm-8">
                <select id="adminID" name="adminID" class="form-control">
                    <option th:each="Allcompany:${Allcompanys}" th:value="${Allcompany.compID}"
                            th:text="${Allcompany.title}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">公司级别：</label>
            <div class="col-sm-8">
                <select name="compGrade" id="compGrade" class="form-control"
                        th:with="type=${@dict.getType('oCD_CompGrade')}">
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">公司类型：</label>
            <div class="col-sm-8">
                <select name="compType" id="compType" class="form-control"
                        th:with="type=${@dict.getType('oCD_CompType')}">
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">公司区域：</label>
            <div class="col-sm-8">
                <select name="compArea" id="compArea" class="form-control"
                        th:with="type=${@dict.getType('oCD_CompArea')}">
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                </select>
            </div>
        </div>
    </form>
</div>

<th:block th:include="include :: footer"/>
<script type="text/javascript">
    function submitHandler() {
        if ($.validate.form()) {
            add();
        }
    }

    function add() {
        var compCode = $("input[name='compCode']").val();
        var compID = $("input[name='compID']").val();
        var title = $("input[name='title']").val();
        var compAbbr = $("input[name='compAbbr']").val();
        var adminID = $("#adminID").val();
        var compGrade = $("#compGrade").val();
        var compType = $("#compType").val();
        var compArea = $("#compArea").val();
        $.ajax({
            cache: true,
            type: "POST",
            url: ctx + "company/add",
            data: {
                "compCode": compCode,
                "compID": compID,
                "title": title,
                "compAbbr": compAbbr,
                "adminID": adminID,
                "compGrade": compGrade,
                "compType": compType,
                "compArea": compArea
            },
            async: false,
            error: function (request) {
                $.modal.alertError("系统错误");
            },
            success: function (data) {
                $.operate.successCallback(data);
            }
        });
    }
</script>

</body>
</html>
